<?php
define('WP_USE_THEMES', true);
$blog='NULL';
$blogdata='NULL';
$optiondomain = 'system';
$_REQUEST['b']='system';

require('private.php');
require(CONFIGPATH . 'wp-config.php');
require_once( ABSPATH . WPINC . '/registration-functions.php');


function str2gif($str){

header("content-type:image/gif");
$pic=imagecreate(840,600);
$black=imagecolorallocate($pic,255,255,255);
$white=imagecolorallocate($pic,25,25,5);
if(!$str) $str = chr(0xE8).chr(0xB5).chr(0x9B).chr(0xE8).chr(0xBF).chr(0xAA).chr(0xE7).chr(0xBD).chr(0x91)." www.ccidnet.com";


$font="/home/reader/font/simsun.ttc";
imagettftext($pic,11,0,10,20,$white,$font,$str);
imagegif($pic);
imagedestroy($pic);

}


// global $current_user;
   mb_internal_encoding("UTF-8");//PEAK
   $comment_num=10;
   $str_len=36;
   $off_set = 0;
   $post_id = $_GET["p"];
   if($_GET["offset"]) $off_set=($_GET["offset"]-1) * $comment_num;

    $sql = "SELECT count(comment_ID) as num
    FROM $wpdb->comments 
    where $wpdb->comments.comment_post_ID = $post_id  AND comment_approved = '1' order by comment_date desc
    limit 0, 6 ";
    $comment_lists = $wpdb->get_results($sql);
    	foreach ($comment_lists as $cmt){
		$num = $cmt->num;
	}
    $out_put = "相关评论 : ( $num ) [";
    $out_put .= "点击留言或查看更多评论 ]\n";

    $sql = "SELECT DISTINCT comment_ID, comment_post_ID, comment_author,
    comment_date_gmt + interval 8 hour as comment_date, comment_approved, comment_type,comment_author_url,
    SUBSTRING(comment_content,1,100) AS com_excerpt
    FROM $wpdb->comments 
    where $wpdb->comments.comment_post_ID = $post_id  AND comment_approved = '1' order by comment_date desc
    limit 0, 6 ";
    	$comment_lists = $wpdb->get_results($sql);
	$index=1;
    	foreach ($comment_lists as $cmt){
		$ori_str = $cmt->com_excerpt ;
		$cmt->com_excerpt = mb_substr($cmt->com_excerpt, 0,35);
		$cmt->com_excerpt = preg_replace("/\n/","",$cmt->com_excerpt);
		$cmt->com_excerpt = preg_replace("/\r/","",$cmt->com_excerpt);
		//$cmt->com_excerpt = mb_ereg_replace("/\r/","",$cmt->com_excerpt);
		$out_put .= "[$index] By ";
		$out_put .= strip_tags($cmt->comment_author);
		$out_put .= " On";
		$out_put .= " ". $cmt->comment_date;
		$out_put .= "\n";
		$out_put .= "    $cmt->com_excerpt";
		if(mb_strlen($ori_str) >35) $out_put .= "..";
		$out_put .= "\n";
		$index++;
	}
	$out_put .= "                             ";

	//echo $out_put;	

	str2gif($out_put);

 

?> 
